@extends('admin.main')

@section('content')
<div class="wrapper wrapper-content">
	<div class="ibox float-e-margins">
		<div class="ibox-title">
			<h5>修改密码</h5>
		</div>
		<div class="ibox-content">
			<form id="frmChangePwd" method="post" class="form-horizontal">
        <div class="form-group">
          <label class="col-sm-2 control-label">当前密码</label>
          <div class="col-sm-6">
            <input type="password" name="curpass" value="" class="form-control" required />
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">新 密 码</label>
          <div class="col-sm-6">
            <input type="password" name="newpass" value="" class="form-control" required />
          </div>
        </div>
				<div class="form-group">
					<label class="col-sm-2 control-label">确认密码</label>
					<div class="col-sm-6">
						<input type="password" name="repass" value="" class="form-control" required />
					</div>
				</div>
				<div class="hr-line-dashed"></div>
				<div class="form-group">
					<div class="col-sm-4 col-sm-offset-2">
						<button class="btn btn-warning btn-w-m" type="submit">修改密码</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
@endsection

@section('pagescript')
<script src="{{asset('assets/models/userModel.js')}}"></script>
<script>
	var artDialog;
  $("#sidebar li[rel='profile']").addClass("active")
    .find("ul").addClass("in")
    .find("li[rel='2']").addClass("active");

	$("#frmChangePwd").submit(function(){
    event.preventDefault();
    var that = this;
    if (this.repass.value != this.newpass.value){
      alert("确认密码有误，请重新输入！");
      this.repass.focus();
      return false;
    }
    $(this).find(":submit").attr("disabled", "disabled");
    var formdata = $(this).serializeArray();
    userModel.changePwd(formdata, function(data){
      var d = dialog({title:null,content:'<i class="fa fa-check-circle"></i>密码修改成功！'}).show();
      setTimeout(function(){d.close().remove();}, 1000);
      that.reset();
      $(that).find(':submit').removeAttr('disabled');
    }, function(data){
      dialog({
        content: '<i class="fa fa-info-circle"></i> ' + data.responseJSON,
        ok: true
      }).showModal();
      $(that).find(':submit').removeAttr('disabled');
    });
    return false;
  });
</script>
@endsection
